package com.mms.dbacess;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

import com.mms.entity.User;
import com.mms.entity.UserRole;import com.mysql.cj.protocol.a.MysqlBinaryValueDecoder;

public class InserUser {
	public static void main(String[] args) throws ClassNotFoundException, SQLException {
		Scanner Changeusername =new Scanner(System.in);
		System.out.println("请输入想添加的用户名");
		String usernameC=Changeusername.next();
		System.out.println("请输入想添加的密码");
		String passwordC=Changeusername.next();
		System.out.println("请输入想添加的状态");
		int enableC=Changeusername.nextInt();
		System.out.println("请输入想添加的角色");
		String roleC=Changeusername.next();
		System.out.println("请输入想添加的管理人员");
		String ManagerC=Changeusername.next();
		String sql="INSERT INTO `user`(`username`,`password`,enabled,role,manager)VALUES(?,?,?,?,?);";
		Class.forName(com.mysql.cj.jdbc.Driver);
//		Connection conn=DriverManager.getConnection("jdbc:Mysql://localhost:3306/grtsmms" , "root", "root");.
//		Class.forName("com.mysql.cj.jdbc.Driver");
		Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/grtsmms", "root", "root");
		PreparedStatement stmt=conn.prepareStatement(sql);
		
		PreparedStatement stme=conn.prepareStatement(sql);
		stme.setString(1, usernameC);
		stme.setString(2, passwordC);
		stme.setInt(3, enableC);
		stme.setString(4, roleC);
		stme.setString(5, ManagerC);
		int re =stme.executeUpdate();
		System.out.println(re);
		stme.close();
		conn.close();
//		static 静态代码段在别的类里加载类的时候执行一次，就再不执行。
	}
}
